package zozopo.warehouse;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.warehouse.operations.PurchaseOS;
import zozopo.warehouse.operations.ReceiptlistOS;
import zozopo.warehouse.operations.ReceiptlistTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class GetLastSalesDateByCustomeridForAjaxAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	//传入参数
	private String customerid = "";

	//传出参数
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/xml; charset=UTF-8");
	}
	
	public String execute(){
		
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
		
		try {
			ReceiptlistTB receiptlist = receiptlistOS.getReceiptlistByCustomerid(customerid);
			if(receiptlist == null){
				response.getWriter().write("新用户!");
			}else{
				response.getWriter().write("上次购买时间:" + receiptlist.getDate_receiptlist() + "");
			}
			
			
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		receiptlistOS.releaseConnection();
		
		
		return NONE;
	} 

	public String getCustomerid() {
		return customerid;
	}

	public void setCustomerid(String customerid) throws UnsupportedEncodingException {
		this.customerid = java.net.URLDecoder.decode(customerid, "UTF-8");
		customerid = customerid.trim();
	}

	
	
}
